<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
</head>
<body>

<div inert>
<iframe height=400 width=600 id="main-iframe">
<frameset rows="*" cols="50,50">
    <frame src="resources/inert-focus-in-frames-frame1.html">
    <frame src="resources/inert-focus-in-frames-frame2.html">
</frameset>
</iframe>
</div>

<script>
setup({ explicit_done: true });

framesLoaded = 0;
numFrames = 4;
var mainIframe = document.getElementById('main-iframe');

function frameLoaded() {
    framesLoaded++;
    if (framesLoaded == numFrames) {
        test(function() {
            var frame1 = mainIframe.contentWindow.frames[0].document;
            var target1 = frame1.querySelector('.target');
            testCanFocus(target1);
            var iframe = frame1.querySelector('iframe').contentDocument;
            testCanFocus(iframe.querySelector('.target'));
        }, "Focus can go into frames or iframes in inert subtree");
        done();
    }
}

function testCanFocus(element) {
    focusedElement = null;
    element.addEventListener('focus', function() { focusedElement = element; }, false);
    element.focus();
    theElement = element;
    assert_equals(focusedElement, theElement);
}

mainIframe.contentDocument.write(mainIframe.textContent);
mainIframe.contentDocument.close();

mainIframe.contentWindow.frames[1].window.onload = frameLoaded;

window.onload = frameLoaded;
</script>
</body>
</html>
